{varType ApiGen\Index\Index $index}
{varType ApiGen\Renderer\Latte\Template\ConfigParameters $config}
{varType ApiGen\Renderer\Latte\Template\LayoutParameters $layout}

{define autoBreakingLine, iterable $items, int $maxWidth, string $indent = ''}
	{pre}
		{var int $width = textWidth($indent)}
		{var Latte\Runtime\HtmlStringable[] $segments = []}

		{capture $before}{include before}{/capture}
		{var $width = $width + htmlWidth($before)}

		{foreach $items as $item}
			{capture $segment}{include item, item: $item}{sep}{include sep}{/sep}{/capture}
			{var $width = $width + htmlWidth($segment) + ($iterator->last ? 0 : 1)}
			{var $segments[] = $segment}
		{/foreach}

		{capture $after}{include after}{/capture}
		{var $width = $width + htmlWidth($after)}

		{if $width <= $maxWidth}
			{$before}
			{foreach $segments as $segment}
				{$segment}
				{sep} {/sep}
			{/foreach}
			{$after}
		{else}
			{$before}{="\n$indent\t"}
			{foreach $segments as $segment}
				{$segment}
				{last}{include sep}{/last}
				{sep}{="\n$indent\t"}{/sep}
			{/foreach}
			{="\n$indent"}{$after}
		{/if}
	{/pre}
{/define}
